package com.ruoyi.manage.cms.service.impl;

import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.common.utils.ListUtil;
import com.ruoyi.common.utils.StrUtil;
import com.ruoyi.manage.cms.domain.HbJrcp;
import com.ruoyi.manage.cms.domain.HbJrjg;
import com.ruoyi.manage.cms.mapper.HbJrcpMapper;
import com.ruoyi.manage.cms.service.IHbJrcpService;
import com.ruoyi.manage.cms.service.IHbJrjgService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 金融产品Service业务层处理
 *
 * @author wangtong
 * @date 2025-07-20
 */
@Service
public class HbJrcpServiceImpl extends ServiceImpl<HbJrcpMapper, HbJrcp> implements IHbJrcpService {

    @Autowired
    private IHbJrjgService iHbJrjgService;

    @Override
    public HbJrcp queryGetById(String id) {
        HbJrcp hbJrcp = this.getById(id);
        return hbJrcp;
    }

    /**
     * 新增金融产品
     *
     * @param hbJrcp 金融产品
     * @return 结果
     */
    @Override
    public boolean addHbJrcp(HbJrcp hbJrcp) {
        if (StrUtil.isNotBlank(hbJrcp.getInstitutionId())) {
            iHbJrjgService.update(new UpdateWrapper<HbJrjg>().eq("id", hbJrcp.getInstitutionId()).setSql("publish_count=publish_count+1"));
        }
        boolean save = this.save(hbJrcp);
        return save;
    }

    /**
     * 修改金融产品
     *
     * @param hbJrcp 金融产品
     * @return 结果
     */
    @Override
    public boolean updateHbJrcp(HbJrcp hbJrcp) {
        return this.updateById(hbJrcp);
    }

    /**
     * 批量删除金融产品
     *
     * @param ids 需要删除的金融产品主键
     * @return 结果
     */
    @Override
    public boolean deleteHbJrcpByIds(String[] ids) {
        return this.removeByIds(ListUtil.toList(ids));
    }

}
